package gitlet;

// TODO: any imports you need here

import java.io.File;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date; // TODO: You'll likely use this in this class
import java.util.List;

/** Represents a gitlet commit object.
 *  TODO: It's a good idea to give a description here of what else this Class
 *  does at a high level.
 *
 *  @author Mark Zhang
 */
public class Commit implements Serializable {
    /**
     *
     * List all instance variables of the Commit class here with a useful
     * comment above them describing what that variable represents and how that
     * variable is used. We've provided one example for `message`.
     */

    /** The message of this Commit. */
    private String message;
    /** The parent of this Commit. */
    private Commit parent;
    /** The second parent reference for merges */
    private Commit secondParent;
    /** The timestamp of this Commit. */
    private String timestamp;
    //the reference of the blob list
    private List<Blob> blob_list;
    // create a new UID for the commit based on the message, parent, and timestamp
    private String UID;

    /** The constructor of the Commit class.
     * @param message the message of the commit
     * @param parent the parent of the commit
     */
    //the commit is identified by the blobs, parent, log message, and commit time

    //TODO: complete the constructor of the commit
    public Commit(String message, Commit parent, String timestamp, List<Blob> blob_list) {
        if (parent == null){ //if the parent is null, then the commit is the initial commit
            //define the parent as null
            this.parent = null;
            this.message = message;
            this.timestamp = timestamp;
            this.blob_list = blob_list;
            //create a new UID for the commit based on the message, parent, and timestamp
            this.UID = Utils.sha1(message, timestamp);
        } else {
            // now we have the parent, message, and timestamp
            this.message = message;
            this.parent = parent;
            this.timestamp = timestamp;
            this.blob_list = blob_list;
            //create a new UID for the commit based on the message, parent, and timestamp
            this.UID = Utils.sha1(message, parent.message, timestamp);
        }
    }

    //get the message of the commit
    public String getMessage() {
        return message;
    }
    //get the parent of the commit
    public Commit getParent() {
        return parent;
    }
    //get the timestamp of the commit
    public String getTimestamp() {
        return timestamp;
    }
    //get the UID of the commit
    public String getUID() {
        return UID;
    }
}
